﻿using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;

namespace SearchInFiles.Lib.Search
{
    public abstract class SearcherAbstract : ISearcher
    {
        public ConcurrentBag<SearchResult> Results { get; private set; }
        public int FrontLength { get; set; }
        public int AfterLength { get; set; }
        public int ResultCount => Results.Count;

        public IEnumerable<SearchResult> GetResults => Results;

        public SearcherAbstract(int FrontLength, int AfterLength)
        {
            this.FrontLength = FrontLength;
            this.AfterLength = AfterLength;
            Results = new();
            
        }
        public abstract bool Search(SearchRequest Request);

        public void Sort()
        {
            Results = new(Results.OrderBy(p => p.SourceFullInfo).ToArray());
        }
    }
}
